from langchain_openai import ChatOpenAI
from browser_use import Agent
from browser_use.browser.browser import Browser, BrowserConfig ##使用自己浏览器
from dotenv import load_dotenv
from pydantic import SecretStr
import os

load_dotenv()

import asyncio

# DEEPSEEK_API_KEY 环境变量
api_key = os.getenv('DEEPSEEK_API_KEY')

#替换为自己浏览器
browser = Browser(
    config=BrowserConfig(
        # NOTE: you need to close your chrome browser - so that this can open your browser in debug mode
        # d:\Learning\AI-related\browser-use-demo\.env注意：您需要关闭您的Chrome浏览器，以便此操作可以在调试模式下打开您的浏览器
        chrome_instance_path=r'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
    )
)

# 初始化模型
llm = ChatOpenAI(
    base_url='https://api.deepseek.com', 
    model='deepseek-chat', 
    api_key=SecretStr(api_key)
)



async def main():
# 使用模型创建代理
    agent = Agent(
      task="",
      llm=llm,
      browser=browser,#打开浏览器设置
      use_vision=False
    )
    # result = await agent.run()
    print(result)

asyncio.run(main())
